#include <bits/stdc++.h>
using namespace std;

// #define ONLINE_JUDGE

#ifndef ONLINE_JUDGE
#define dbg(x...)                             \
	{                                         \
		cerr << "\033[32;1m" << #x << " -> "; \
		err(x);                               \
	}
void err()
{
	cerr << "\033[39;0m" << endl;
}
template <typename T, typename... A>
void err(T a, A... x)
{
	cerr << a << ' ';
	err(x...);
}
#else
#define dbg(...)
#endif

class Solution
{
	typedef long long LL;
	const static int N = 5e4 + 50;
	struct segT
	{
		LL lazy[N << 2], dat[N << 2];
		int nn;

		int L, R;
		inline void pu(int rt)
		{
			dat[rt] = max(dat[rt << 1], dat[rt << 1 | 1]);
		}

		inline void pd(int rt)
		{
			if (lazy[rt])
			{
				int ls = rt << 1, rs = rt << 1 | 1;
				lazy[ls] += lazy[rt];
				lazy[rs] += lazy[rt];
				dat[ls] += lazy[rt];
				dat[rs] += lazy[rt];
				lazy[rt] = 0;
			}
		}
		void init(LL a[], int n)
		{
			nn = 1;
			while (nn < n)
				nn <<= 1;
			for (int i = 1; i <= n; ++i)
				dat[i + nn - 1] = a[i];
			for (int i = n + nn; i < 2 * nn; ++i)
				dat[i] = 0;
			for (int i = nn - 1; i >= 1; --i)
				pu(i);
		}

		void upt(int l, int r, int rt, int v)
		{
			if (L <= l && r <= R)
			{
				dat[rt] += v;
				lazy[rt] += v;
				return;
			}
			int m = (l + r) >> 1;
			pd(rt);
			if (L <= m)
				upt(l, m, rt << 1, v);
			if (m + 1 <= R)
				upt(m + 1, r, rt << 1 | 1, v);
			pu(rt);
		}

		LL q(int l, int r, int rt)
		{
			if (L <= l && r <= R)
			{
				return dat[rt];
			}
			int m = (l + r) >> 1;
			pd(rt);
			LL v1 = 0, v2 = 0;
			if (L <= m)
				v1 = q(l, m, rt << 1);
			if (m + 1 <= R)
				v2 = q(m + 1, r, rt << 1 | 1);
			pu(rt);
			return max(v1, v2);
		}

		inline void u(int l, int r, int v)
		{
			L = l;
			R = r;
			upt(1, nn, 1, v);
		}
		inline LL q(int l, int r)
		{
			L = l;
			R = r;
			return q(1, nn, 1);
		}

		int lower_bound(int v, int l, int r, int rt)
		{
			if (dat[rt] < v)
				return -1;
			if (l == r)
				return l;
			int m = (l + r) >> 1, ls = rt << 1, rs = rt << 1 | 1;
			pd(rt);
			int res = 0;
			if (dat[ls] >= v)
				res = lower_bound(v, l, m, ls);
			else
				res = lower_bound(v, m + 1, r, rs);
			pu(rt);
			return res;
		}

		inline int lower_bound(int v)
		{
			return lower_bound(v, 1, nn, 1);
		}
	} seg;

	int a[N], n;
	LL s[N];

public:
	int shortestSubarray(vector<int> &A, int K)
	{
		n = A.size();
		for (int i = 1; i <= n; ++i)
			a[i] = A[i - 1];
		s[0] = 0;
		for (int i = 1; i <= n; ++i)
			s[i] = s[i - 1] + a[i];

		seg.init(s, n);
		int ans = n + 1;
		for (int i = 1; i <= n; ++i)
		{
			// for (int j = 1; j <= n; ++j)
			// 	dbg(i, j, seg.q(j, j));
			if (seg.q(1, n) >= K)
			{
				ans = min(ans, seg.lower_bound(K) - i + 1);
			}
			if (i == n)
				break;
			seg.u(i, n, -a[i]);
		}
		if (ans == n + 1)
			return -1;
		else
			return ans;
	}
} sol;
int main(int argc, char const *argv[])
{

	vector<int> a = {77, 19, 35, 10, -14};
	printf("%d\n", sol.shortestSubarray(a, 19));
	return 0;
}